//
//  MYGFriendsChatViewController.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/4/15.
//

import UIKit
import QMUIKit

class MYGFriendsChatViewController: MYGBaseController {

    override func viewDidLoad() {
        super.viewDidLoad()

        configUI()
    }
    private func configUI() {
        title = "好友沟通"
        view.backgroundColor = .white
        view.addSubview(stackView)
        
        stackView.addArrangedSubviews([searchTextField, memberButton, addButton])
        stackView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(18)
            make.top.equalToSuperview()
            make.height.equalTo(navHeight)
        }
        
        searchTextField.snp.makeConstraints { make in
            make.height.equalTo(30)
        }
        memberButton.setContentHuggingPriority(.required, for: .horizontal)
        memberButton.setContentCompressionResistancePriority(.required, for: .horizontal)
        addButton.setContentHuggingPriority(.required, for: .horizontal)
        addButton.setContentCompressionResistancePriority(.required, for: .horizontal)
        
        view.addSubview(tableView)
        view.addSubview(searchButton)
        tableView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(stackView.snp.bottom)
        }
        
        searchButton.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-123)
            make.width.height.equalTo(43)
            make.right.equalToSuperview().offset(-20)
        }
    }

    // MARK: - lazy load
    private lazy var stackView: UIStackView = {
        let stackV = UIStackView()
        stackV.axis = .horizontal
        stackV.spacing = 10
        stackV.alignment = .center
        return stackV
    }()
    
    
    private lazy var searchTextField: UITextField = {
        let tf = UITextField()
        tf.font = .regular(14)
        tf.textColor = .rgba(51, 51, 51)
        tf.backgroundColor = .rgba(243, 243, 243, 1)
        tf.layer.masksToBounds = true
        tf.layer.cornerRadius = 15
        tf.attributedPlaceholder = NSMutableAttributedString.rz.colorfulConfer(confer: { confer in
            confer.image(UIImage(named: "Chat/search"))
            confer.text(" 搜索")?.font(.regular(14)).textColor(.rgba(142, 142, 147, 1))
        })
        tf.textAlignment = .center
       // tf.addTarget(self, action: #selector(textValueChanged), for: .editingChanged)
        //tf.delegate = self
        return tf
    }()
   
    
    private lazy var memberButton: UIButton = {
        let btn = UIButton()
        btn.setBackgroundImage(UIImage(named: "photo"), for: .normal)
        //btn.addTarget(self, action: #selector(clickButton), for: .touchUpInside)

        return btn
    }()
    
    private lazy var addButton: UIButton = {
        let btn = UIButton()
        btn.setBackgroundImage(UIImage(named: "add"), for: .normal)
       // btn.addTarget(self, action: #selector(clickButton), for: .touchUpInside)
        return btn
    }()
    
    
    private lazy var searchButton: QMUIButton = {
        let btn = QMUIButton()
//        btn.setTitle("陌生\n信息", for: .normal)
//        btn.setTitleColor(.white, for: .normal)
//        btn.imagePosition = .left
//        btn.titleLabel?.font = .regular(12)
//        btn.spacingBetweenImageAndTitle = 3
//        btn.backgroundColor = .rgba(32, 92, 255, 1)
        btn.layer.masksToBounds = true
        btn.layer.cornerRadius = 21
        btn.setBackgroundImage(UIImage(named: "Chat/tip"), for: .normal)
        //btn.addTarget(self, action: #selector(clickButton), for: .touchUpInside)

        return btn
    }()

    private lazy var tableView: UITableView = {
        let tableV = UITableView()
        tableV.delegate = self
        tableV.dataSource = self
        tableV.separatorStyle = .none
        tableV.backgroundColor = .white
        tableV.register(cellWithClass: MYGFriendsChatTableViewCell.self)
        return tableV
    }()
    
}

extension MYGFriendsChatViewController : UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        5
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        70
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withClass: MYGFriendsChatTableViewCell.self, for: indexPath)
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
//        let vc = MYGChatController(sessionId: 0, title: <#String#>)
//        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    
}
